/*
 * mod_motor_software_protection.h
 *
 *  Created on: 2025 Apr 10
 *      Author: SFLY
 */

#ifndef XTFOCLIB_MODULES_MOD_PROTECTION_H_
#define XTFOCLIB_MODULES_MOD_PROTECTION_H_
#include "bsp_board_config.h"

typedef struct{
float     AbnormalHighVbus;    //异常高母线电压
float     AbnormalLowVbus;     //异常低母线电压
float     OvpVbusThreshold;    //过母线电压阈值
float     UvpVbusThreshold;    //欠母线电压阈值
int32_t   AbnormalCnt;
int32_t   AbnormalTime;
int32_t   OvpCnt;
int32_t   OvpTime;
int32_t   UvpCnt;
int32_t   UvpTime;
int32_t   ErrClrTime;
}xt_hal_Vbus_Monitor_t;

typedef struct{
float     OvpTempThreshold;    //过温阈值
int32_t   OvpCnt;
float     OvpTime;
int32_t   ErrClrTime;
}xt_hal_Temp_Monitor_t;

typedef struct{
float     OvpCurrentThreshold; //过流阈值
int32_t   OvpCnt;
float     OvpTime;
int32_t   ErrClrTime;
}xt_hal_Current_Monitor_t;

typedef struct{
    xt_hal_Vbus_Monitor_t    motor_vbus_monitor;
    xt_hal_Temp_Monitor_t    motor_temp_monitor;
    xt_hal_Current_Monitor_t motor_current_monitor;
    uint32_t ErrorFlag;
    void (*motor_vbus_monitor_update)(float, void*);
    void (*motor_current_monitor_update)(float,float,float,void*);
    void (*motor_temp_monitor_update)(float,void*);
}xt_hal_Motor_Protector_t;

void Hal_Motor_Protector_Init(xt_hal_Motor_Protector_t *motor_protector);
void Hal_Motor_VBus_Monitor_Update(float VBus,void *motor_protector_ptr);
void Hal_Motor_Current_Monitor_Update(float Iu,float Iv,float Iw,void *motor_protector_ptr);
void Hal_Motor_Temp_Monitor_Update(float Temp,void *motor_protector_ptr);

#endif /* XTFOCLIB_MODULES_MOD_PROTECTION_H_ */
